'''Copyright 2009 Marcus Wanner, Colin Rooney

This file is part of the Python Debug Logging Suite.

The Python Debug Logging Suite is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

The Python Debug Logging Suite is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with The Python Debug Logging Suite.  If not, see
<http://www.gnu.org/licenses/>.

Display server for the debuglive module.'''

import socket, time

host = 'localhost'
port = 61307

servesock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
servesock.bind((host, port))
print 'Listening for datagrams on port '+str(port)+' of '+host+'.'

while 1:
    inmsg, addr = servesock.recvfrom(1024)
    
    if inmsg == '_PING_SERVER':
        
        pingsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        pingsock.sendto('_PING_SUCCESS', ('localhost', 38477))

        print 'Server was pinged.'

        continue
    print inmsg
